#include <cstdio>
#include <thread>
#include "vl_dispatcher.h"

using namespace VL;

// 测试用例1
// dispatch start quit
void instance1() {
	dispatcher d;
	std::thread t([&] {
		std::this_thread::sleep_for(std::chrono::seconds(2));
		d.quit();
	});
	int num = 0;
	d.dispatch_run([&]{
		num = 1;
	});
	d.start();
	if(num != 1) {
		exit(1);
	}
	t.join();
}

// 测试用例2
// dispatcher start_sync quit_safe
void instance2() {
	dispatcher d;
	int num = 0;
	d.dispatch_run([&]{
		num = 1;
	});
	std::thread t([&] {
		d.quit_safety();
	});
	d.start_sync();
	if(num != 1) {
		exit(1);
	}
	t.join();
}

// 测试用例3
// async_dispatcher start
void instance3() {
	async_dispatcher d;
	int num = 0;
	d.dispatch_run([&]{
		num = 1;
	});
	std::thread t([&] {
		d.quit_safety();
	});
	d.start_sync();
	d.quit_safety_sync();
	if(num != 1) {
		exit(1);
	}
	t.join();
}

void instance4() {
	async_dispatcher d;
	d.start();
	d.quit_safety();
	d.dispatch_run([] {

	});
}


int main(int argc, const char ** argv) {
	// instance1();
	// printf("instance1 pass\n");
	// instance2();
	// printf("instance2 pass\n");
	instance3();
	printf("instance3 pass\n");
	instance4();
	printf("instance4 pass\n");
	return 0;
}